package csu.web.dining.service.impl;

import csu.web.dining.domain.Account;
import csu.web.dining.persistence.impl.AccountDaoImpl;
import csu.web.dining.service.AccountService;
import csu.web.dining.persistence.AccountDao;

public class AccountServiceImpl implements AccountService {
    private AccountDao accountDao;
    private String msg = null;

    public AccountServiceImpl()
    {
        this.accountDao=new AccountDaoImpl();
    }

    //登录
    @Override
    public Account login(String username, String password) {
        return accountDao.getAccountByUsernameAndPassword(username,password);

    }

    //注册
    @Override
    public void register(Account account) {
        accountDao.insertAccount(account);
        accountDao.insertProfile(account);
        accountDao.insertSignon(account);
    }

    //通过用户名寻找账户
    @Override
    public Account findAccountByUsername(String username) {
        return accountDao.getAccountByUsername(username);
    }

    //更新账户
    @Override
    public void updateAccount(Account account) {
        accountDao.updateAccount(account);
        accountDao.updateProfile(account);
        if (account.getPassword() != null && account.getPassword().length() > 0) {
            accountDao.updateSignon(account);
        }
    }

    //寻找邮箱
    @Override
    public String findEmail(Account account) {
        return accountDao.getAccountByUsername(account.getUsername()).getEmail();
    }

    //重置密码
    @Override
    public int resetPassword(Account account) {
        return accountDao.updateSignon(account);
    }
}
